package com.example.mycomposelesson.ui

import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.viewmodel.compose.viewModel
import com.example.mycomposelesson.Greeting
import com.example.mycomposelesson.MyApplication.Companion.logger
import com.example.mycomposelesson.ui.theme.MyComposeLessonTheme
import com.example.mycomposelesson.ui.viewmodel.MainActivityViewModel

@Composable
fun SerialDataListWithVM(viewModel: MainActivityViewModel = viewModel())
{
    val serialdatalist = viewModel.serialdataList
    serialdatalist?.let{
        logger.debug { "串口数据已变化:${it.size}" }
        SerialDataList(it.toList())
    }
}
@Composable
fun  SerialDataList(serialDatalist:List<String>){
    LazyColumn{
        items(serialDatalist){item->
            Greeting(item)
        }
    }
}
@Preview(name = "串口数据列表",showBackground = true)
@Composable
fun prevSerialDataList(){
    MyComposeLessonTheme{
        SerialDataList(listOf("数据1","数据1","数据1","数据1","数据1"))
    }
}